<?php

namespace App\Supports\Payment\Methods\Wxpay;

use Carbon\Carbon;
use App\Models\Order;
use App\Models\OrderRefund;
use Illuminate\Support\Facades\DB;
use App\Events\OrderRefundedEvent;
use App\Supports\Payment\Methods\Method;
use App\Supports\Payment\Contracts\MethodCallback;

class CallbackOrderRefund extends Method implements MethodCallback
{
	public function markAsPaid($order = null, $data = null)
	{
		DB::transaction(function () use ($order, $data) {
			
			$orderData['has_refund'] = true;
			
			$order->update($orderData);
			
			//event(new OrderRefundedEvent($refund));
		});
	}
	
	public function callback($data = null)
	{
		
		if (!$order = Order::where('number', $data['out_refund_no'])->first()) {
			return 'fail';
		}
		
		if ($order and $order->isPaid()) {
			$this->markAsPaid($order, $data);
		}
		
		return $this->channel->success();
	}
}
